

#include "steambehemoth.h"
#include "gamemanager.h"
#include "gamedatamanager.h"
#include "CCSkeletalSprite.h"
#include "bullet.h"
#include "log.h"
#include "messagequeue.h"
#include "gamescene.h"

#define __super         Unit

SteamBehemoth::SteamBehemoth() {

}

SteamBehemoth::~SteamBehemoth() {

}

void SteamBehemoth::init(UnitInfo const & info, float unitScale) {
	__super::init(info, unitScale);
}

void SteamBehemoth::update(float ticks) {
	__super::update(ticks);
}

void SteamBehemoth::handleStateBirth(float ticks){
	transformState(UnitState::idle);
}

void SteamBehemoth::handleStateAim(float ticks){

}

void SteamBehemoth::handleStateAttack(float ticks){
	if (sprite->animationIsDone()) {
		transformState(UnitState::idle);
	}
}

void SteamBehemoth::handleStateDying(float ticks){
	if (sprite->animationIsDone()) {
		transformState(UnitState::died);
	}
}

void SteamBehemoth::handleStateIdle(float ticks){
	if (gameScene->battleState == BattleState::standby) {
		return;
	}

	if (_timeElapsed >= attribute.reloadTime) {
		if(target) {
			transformState(UnitState::attack);
		}
	}
}

void SteamBehemoth::handleStateReload(float ticks){

}

void SteamBehemoth::handleStateWalk(float ticks){
	if (gameScene->battleState == BattleState::standby) {
		transformState(UnitState::idle);
	} else {
		move(ticks);

		if (arrivedTargetPosition) {
			transformState(UnitState::idle);
		} else if (_timeElapsed >= attribute.reloadTime) {
			if(target) {
				transformState(UnitState::walk_attack);
			}
		}
	}
}

void SteamBehemoth::handleStateWalkAim(float ticks){

}

void SteamBehemoth::handleStateWalkAttack(float ticks){
	if (sprite->animationIsDone()) {
		transformState(UnitState::walk);
	}
}

void SteamBehemoth::handleStateWalkReload(float ticks){

}

void SteamBehemoth::onAttack() {
	if (target) {
		Bullet *bullet = new Bullet(&attribute);
		bullet->init();
		target->addBullet(bullet);
	}

	_timeElapsed = 0;
}
